﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WiMo.Games.MathLib.Calculus
{
    public class ODESolver
    {
        public static void RungeKutta(ODE eq, float ds)
        {
            var dq1 = eq.GetRightHandSide(eq.S, eq.Q, eq.Q, ds, 0.0f);
            var dq2 = eq.GetRightHandSide(eq.S + 0.5f * ds, eq.Q, dq1, ds, 0.5f);
            var dq3 = eq.GetRightHandSide(eq.S + 0.5f * ds, eq.Q, dq2, ds, 0.5f);
            var dq4 = eq.GetRightHandSide(eq.S, eq.Q, dq3, ds, 1.0f);
           
            for(var idx = 0; idx < eq.QtyEquations; idx++)
            {
                eq.Q[idx] = eq.Q[idx] + (dq1[idx] + 2.0f*dq2[idx] + 2.0f*dq3[idx] + dq4[idx]) / 6.0f;
            }

            eq.S += ds;

        }
    }
}
